# Copyright (c) 2005-2009 Nokia Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import e32
import unittest
import messaging
from sniffylib.rpc import socketsms



NUMBER = '+48723073407'
s60_version = e32.s60_version_info

class InboxModuleTest(unittest.TestCase):
    sender = 'Msg_Testing'
    msg = u"Hi from PyS60"
    prefix = 'TEST '

    def __init__(self, methodName='runTest'):
        unittest.TestCase.__init__(self, methodName=methodName)
        self.sms_service = socketsms.SmsService()
        self.sms_service.sms_handler = self.inbox_callback
        self.sms = None
        
    def send_sms(self, content):
        messaging.sms_send(NUMBER,
                           content, '7bit', None, self.sender)
        e32.ao_sleep(10)

    def setUp(self):
        self.sms_service.start()
        
    def inbox_callback(self, sms):
        self.sms = sms

    def test_should_intercept(self):
        self.send_sms('TEST ' + self.msg)
        self.failIf(self.sms is None, "The message was not intercepted")
        self.failUnlessEqual(self.sms.content,
                             self.message,
                             "The message contents are not proper")

    def test_should_not_intercept(self):
        self.send_sms(self.msg)
        self.failIf(self.sms, "The message was intercepted")

    def tearDown(self):
        self.sms_service.stop()
        self.sms = None
